package com.tony.juc.timeUtil;

import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: TimeUtilDemo001
 * @Auther: 皮蛋布丁
 * @Date: 2022/04/03/21:52
 * @Description:
 */
public class TimeUtilDemo001 {
    public static void main(String[] args) {
        long hour = 1;
        //小时转秒钟
        /*long second = TimeUnit.SECONDS.convert(hour,TimeUnit.HOURS);    //由小时转为秒数
        System.out.println("小时转秒数："+ second);*/

        //小时转分钟
        /*long second = TimeUnit.MINUTES.convert(hour,TimeUnit.HOURS);
        System.out.println("小时转分钟："+ second);*/

        //天数转秒钟
        /*long day = 1;
        long second = TimeUnit.SECONDS.convert(day,TimeUnit.DAYS);  //由天转为秒
        System.out.println("一天的秒数：" + second);*/

        //时间间隔
        /*Duration duration = Duration.ofHours(2).plusHours(2);   //2小时+2小时
        System.out.println("时间间隔：" + duration.toHours());
        long second = TimeUnit.SECONDS.convert(duration);
        System.out.println("间隔的秒数：" + second);*/

        //当前时间戳加上天数
        /*long current = System.currentTimeMillis(); //获取当前时间戳
        long after = current + TimeUnit.MILLISECONDS.convert(180,TimeUnit.DAYS);
        System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(new Date(after)));*/

        //根据秒数来休眠
        /*for (int i = 0; i < 100; i++) {
            try {
                TimeUnit.SECONDS.sleep(2);  //根据秒来休眠
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("【x = " + i + "】");
        }*/
    }

}
